package Thread;

import java.util.Scanner;

public class Demo25 {
    public static void main(String[] args) {
        Object lock = new Object();
        Thread t1 = new Thread(()->{
            try{
                System.out.println("t1 wait 之前");
                synchronized (lock) {
                    lock.wait();
                }
                System.out.println("t1 wait 之后");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        Thread t2 = new Thread(()->{
            try{
                System.out.println("t2 wait 之前");
                synchronized (lock) {
                    lock.wait();
                }
                System.out.println("t2 wait 之后");

            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
//        Thread t3 = new Thread(()->{
//            Scanner sc = new Scanner(System.in);
//            System.out.println("输入任意唤醒线程");
//            sc.next();
//            synchronized(lock) {
//                lock.notify();
//            }
//            System.out.println("输入任意唤醒另一线程");
//            sc.next();
//            synchronized(lock) {
//                lock.notify();
//            }
//        });
        Thread t4 = new Thread(()->{
            Scanner sc = new Scanner(System.in);
            System.out.println("输入任意唤醒全部");
            sc.nextLine();
            synchronized (lock) {
                lock.notifyAll();
            }
        });
        t1.start();
        t2.start();
        t4.start();
//        t3.start();
    }
}
